{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bdf2338e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "215 ms ± 2.92 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "module 'cv2' has no attribute 'setUserOptimized'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[2], line 11\u001b[0m\n\u001b[0;32m      7\u001b[0m img \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mones((\u001b[38;5;241m1500\u001b[39m,\u001b[38;5;241m1500\u001b[39m,\u001b[38;5;241m3\u001b[39m),np\u001b[38;5;241m.\u001b[39muint8)\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m255\u001b[39m\n\u001b[0;32m      9\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39mrun_line_magic(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtimeit\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mres = cv.medianBlur(img,49)\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m---> 11\u001b[0m \u001b[43mcv\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msetUserOptimized\u001b[49m(\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[0;32m     12\u001b[0m \u001b[38;5;28mprint\u001b[39m(cv\u001b[38;5;241m.\u001b[39museOptimized())\n\u001b[0;32m     14\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39mrun_line_magic(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtimeit\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mres = cv.medianBlur(img,49)\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'cv2' has no attribute 'setUserOptimized'"
     ]
    }
   ],
   "source": [
    "import cv2 as cv\n",
    "import numpy as np\n",
    "#openCV性能优化\n",
    "cv.setUseOptimized(True)\n",
    "print(cv.useOptimized())\n",
    "\n",
    "img = np.ones((1500,1500,3),np.uint8)*255\n",
    "\n",
    "%timeit res = cv.medianBlur(img,49)\n",
    "\n",
    "cv.setUserOptimized(False)\n",
    "print(cv.useOptimized())\n",
    "\n",
    "%timeit res = cv.medianBlur(img,49)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d581917a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
